<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class GuideModel extends CI_Model{
	function __construct()
	{
		parent::__construct();
		$this->load->database();
	}

	public function gettype($uid=0)
	{
		if (!is_numeric($uid) && ($uid < 0)) return false;

		if ($uid>0) {
			//kiểm tra uid đầu vào là student hay teacher
			// $this->db->select('type');
			// $this->db->from('user');
			// $this->db->where('id', 1);
			// $type= $this->db->get();

			$type= $this->db->query("SELECT * from user where id= $uid");
			//var_dump($type->first_row());
			return $type->first_row()->type;
			// if ($type == 1) {
			// 	return 1;
			// }else if ($type == 0) {
			// 	return 0;
			// }
		}
	}

	public function getguide($uid=0)
	{
		if (!is_numeric($uid) && ($uid < 0)) return false;
		if ($uid>0) {
			$this->load->model('GuideModel');
			$type= $this->GuideModel->gettype($uid);
			if($type== 1) {
				$q= $this->db->query("SELECT * from manage_student where student_id= $uid");
			}else if($type== 0) {
				$q= $this->db->query("SELECT * from manage_student where teacher_id= $uid");
			}
			return $q->result();
		}
	}
}
?>